package cn.iocoder.yudao.module.fengdong.smartelderly.dal.mysql.commodity;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.commodity.CommodityDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.commodity.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 商品 Mapper
 *
 * @author 沣东养老院管理员
 */
@Mapper
public interface CommodityMapper extends BaseMapperX<CommodityDO> {

    default PageResult<CommodityDO> selectPage(CommodityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CommodityDO>()
                .eqIfPresent(CommodityDO::getType, reqVO.getType())
                .likeIfPresent(CommodityDO::getName, reqVO.getName())
                .eqIfPresent(CommodityDO::getImageurls, reqVO.getImageurls())
                .eqIfPresent(CommodityDO::getSellNum, reqVO.getSellNum())
                .eqIfPresent(CommodityDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(CommodityDO::getContent, reqVO.getContent())
                .eqIfPresent(CommodityDO::getPoint, reqVO.getPoint())
                .eqIfPresent(CommodityDO::getInventory, reqVO.getInventory())
                .eqIfPresent(CommodityDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CommodityDO::getOthers, reqVO.getOthers())
                .betweenIfPresent(CommodityDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CommodityDO::getId));
    }

    default List<CommodityDO> selectList(CommodityExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CommodityDO>()
                .eqIfPresent(CommodityDO::getType, reqVO.getType())
                .likeIfPresent(CommodityDO::getName, reqVO.getName())
                .eqIfPresent(CommodityDO::getImageurls, reqVO.getImageurls())
                .eqIfPresent(CommodityDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(CommodityDO::getSellNum, reqVO.getSellNum())
                .eqIfPresent(CommodityDO::getContent, reqVO.getContent())
                .eqIfPresent(CommodityDO::getPoint, reqVO.getPoint())
                .eqIfPresent(CommodityDO::getInventory, reqVO.getInventory())
                .eqIfPresent(CommodityDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CommodityDO::getOthers, reqVO.getOthers())
                .betweenIfPresent(CommodityDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CommodityDO::getId));
    }

    IPage<CommodityRespIpageVO> getCommodityIPage(IPage page, @Param("param") CommodityIPageReqVO pageVO);
}
